﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using TEST;

namespace D_Enecrypt
{
	public partial class form1 : Form
	{
		public form1()
		{
			InitializeComponent();
		}

		private void btnEn_Click(object sender, EventArgs e)
		{
			string key = tbKey.Text;
			if (key.Length < 32)
				MessageBox.Show("秘钥错误。");
			else
			{
				CreditCardInfo cardInfo = new CreditCardInfo
				{
					cardholderMobile = tbCertMob.Text.ECBEncryptByPKCS(key),
					cardholderName = tbUser.Text.ECBEncryptByPKCS(key),
					certNo = tbCertNo.Text.ECBEncryptByPKCS(key),
					certType = tbCertType.Text.ECBEncryptByPKCS(key),
					creditCardNo = tbcardNo.Text.ECBEncryptByPKCS(key),
					creditCardType = tbCardType.Text.ECBEncryptByPKCS(key),
					validDate = tbValiDate.Text.ECBEncryptByPKCS(key),
					verifyCode = tbValiCode.Text.ECBEncryptByPKCS(key)
				};
				//string s = string.Empty;
				//XmlSerializer ser = new XmlSerializer(cardInfo.GetType());
				//using (MemoryStream stream = new MemoryStream(100))
				//{
				//	ser.Serialize(stream, cardInfo);
				//	stream.Position = 0;
				//	using (StreamReader reader = new StreamReader(stream,Encoding.UTF8))
				//	{
				//		s = reader.ReadToEnd();
				//	}
				//}
				string result = cardInfo.Serializer();
				tbReslt.Text = result;
			}
		}
		private void btnDe_Click(object sender, EventArgs e)
		{
			string key = tbKey.Text;
			if (key.Length < 32)
				MessageBox.Show("秘钥错误。");
			else
			{
				string result = "卡种：" + tbCardType.Text.ECBDecryptByPKCS(key) + "\r\n"
					+ "卡号：" + tbCertNo.Text.ECBDecryptByPKCS(key) + "\r\n"
					+ "验证码：" + tbValiCode.Text.ECBDecryptByPKCS(key) + "\r\n"
					+ "有效期：" + tbValiDate.Text.ECBDecryptByPKCS(key) + "\r\n"
					+ "持卡人：" + tbUser.Text.ECBDecryptByPKCS(key) + "\r\n"
					+ "持卡人手机：" + tbCertMob.Text.ECBDecryptByPKCS(key) + "\r\n"
					+ "证件类型：" + tbCertType.Text.ECBDecryptByPKCS(key) + "\r\n"
					+ "证件号：" + tbcardNo.Text.ECBDecryptByPKCS(key) + "\r\n";
				tbReslt.Text = result;
			}
		}
	}
}
